package com.wzp.algorithm.must;

import java.util.Arrays;

public class BiSearch {

    //  二分查找
    public static int biSearch(int[] array, int value) {
        int low = 0;
        int high = array.length - 1;
        int mid;
        while (low <= high) {
            mid = (high - low) / 2 + low;
            if (array[mid] > value) {
                high--;
            } else if (array[mid] < value) {
                low++;
            } else {
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 5};
        System.out.println(biSearch(arr, 5));

    }

}
